<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05员工表格练习</title>
</head>
<body>
<input type="text" placeholder="请输入员工姓名" id="i1">
<input type="text" placeholder="请输入员工工资" id="i2">
<input type="text" placeholder="请输入员工岗位" id="i3">
<button onclick="add()">添加员工</button>
<hr>
<table border="1px">
    <caption>员工表</caption>
    <tr>
        <th>姓名</th>
        <th>工资</th>
        <th>岗位</th>
    </tr>

    <script>
        let arr=[];
        function add() {
            var name = document.getElementById('i1').value;
            var salary = document.getElementById('i2').value;
            var position = document.getElementById('i3').value;

            var tr = document.createElement('tr');
            var td1 = document.createElement('td');
            var td2 = document.createElement('td');
            var td3 = document.createElement('td');
            td1.innerHTML = name;
            td2.innerHTML = salary;
            td3.innerHTML = position;
            tr.append(td1,td2,td3);
            console.log(tr);
            var table = document.querySelector('table');
            table.append(tr);
            document.getElementById('i1').value='';
            document.getElementById('i2').value='';
             document.getElementById('i3').value='';
arr.push({name, salary, position});
console.log(arr);
        }

    </script>
</table>
</body>
</html>